package com.guoyh.procommon

import android.app.Application
import com.alibaba.android.arouter.launcher.ARouter
import com.guoyh.bilui.InitLibUiUtils
import com.guoyh.baseutils.InitCommonUtils
import com.guoyh.baseutils.mylog.Loger
import com.guoyh.billocal.InitLocal
import com.guoyh.xprodatas.InitProNet
import com.scwang.smart.refresh.footer.ClassicsFooter
import com.scwang.smart.refresh.header.ClassicsHeader
import com.scwang.smart.refresh.layout.SmartRefreshLayout
import com.tencent.smtt.sdk.QbSdk
import com.tencent.smtt.sdk.QbSdk.PreInitCallback

/**
 * @CreateDate: 7/20/21 10:37 AM
 * @Author: guoyh
 * @Description: java类作用描述
 */
object InitAll {
    fun initAll(application: Application) {
        ARouter.openDebug()
        ARouter.openLog()
        ARouter.init(application)
        InitCommonUtils.initCommonUtils(application)
        InitProNet.initProNet(application)
        InitLibUiUtils.initLibUiUtils(application)
        initSmartRefresh()
        initX5(application)
        InitLocal.init(application)

    }

    private fun initSmartRefresh() {
        SmartRefreshLayout.setDefaultRefreshHeaderCreator { context, _ -> ClassicsHeader(context) }
        SmartRefreshLayout.setDefaultRefreshFooterCreator { context, _ -> ClassicsFooter(context) }
    }

    private fun initX5(application: Application) {
        //搜集本地tbs内核信息并上报服务器，服务器返回结果决定使用哪个内核。
        val cb: PreInitCallback = object : PreInitCallback {
            override fun onViewInitFinished(arg0: Boolean) {
                //x5內核初始化完成的回调，为true表示x5内核加载成功，否则表示x5内核加载失败，会自动切换到系统内核。
                Loger.dd("onViewInitFinished is $arg0")
            }

            override fun onCoreInitFinished() {}
        }
        //x5内核初始化接口
        QbSdk.initX5Environment(application, cb)
    }

}